<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Bus Errors</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('page_user_guide_bus_errors.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Bus Errors </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#section_user_guide_dev_info_status">Obtaining Bus Status Information</a></li>
<li class="level1"><a href="#section_user_guide_send_recv_overruns">Overruns</a></li>
<li class="level1"><a href="#section_user_guide_bus_errors_error_frames">Error Frames</a></li>
<li class="level1"><a href="#section_user_guide_bus_errors_sja1000_error_codes">SJA1000 Error Codes</a></li>
</ul>
</div>
<div class="textblock"><h1><a class="anchor" id="section_user_guide_dev_info_status"></a>
Obtaining Bus Status Information</h1>
<p>Use <a class="el" href="group___c_a_n.html#gadb3a712bd123317043cb73e1008075c8">canReadErrorCounters()</a> to read the error counters of the CAN controller. There are two such counters in a CAN controller (they are required by the protocol definition).</p>
<dl class="section note"><dt>Note</dt><dd>Not all CAN controllers allow access to the error counters, so CANlib may provide you with an "educated guess" instead.</dd></dl>
<p>Use <a class="el" href="group___c_a_n.html#gaca3da209fe673b3838a50a3abe831855">canReadStatus()</a> to obtain the bus status (error active, error passive, bus off; as defined by the CAN standard).</p>
<h1><a class="anchor" id="section_user_guide_send_recv_overruns"></a>
Overruns</h1>
<p>If the CAN interface or the driver runs out of buffer space, or if the bus load is so high that the CAN controller can't keep up with the traffic, an overload condition is flagged to the application.</p>
<p>The driver will set the <a class="el" href="canstat_8h.html#ae441634e38d57eb789936f5ac745410b">canMSGERR_HW_OVERRUN</a> and/or <a class="el" href="canstat_8h.html#a810afd58f22df8c44c729f78d955e006">canMSGERR_SW_OVERRUN</a> flags in the flag argument of <a class="el" href="group___c_a_n.html#ga157d49a9343dea68ac953145e02266d8">canRead</a> and its relatives. The flag(s) will be set in the first message read from the driver after the overrun or overload condition happened.</p>
<p>Not all hardware platforms can detect the difference between hardware overruns and software overruns, so your application should test for both conditions. You can use the symbol <a class="el" href="canstat_8h.html#adf0d578c7b25ede29a9733da44f08ab3">canMSGERR_OVERRUN</a> for this purpose.</p>
<h1><a class="anchor" id="section_user_guide_bus_errors_error_frames"></a>
Error Frames</h1>
<p>When a CAN controller detects an error, it transmits an error frame. This is a special CAN message that causes all other CAN controllers on the bus to notice that an error has occurred.</p>
<p>CANlib will report error frames to the application just like it reports any other CAN message, but the <a class="el" href="canstat_8h.html#ade1b8ed815a4bc6ada6ec666e48e9cf8">canMSG_ERROR_FRAME</a> flag will be set in the flags parameter when e.g. <a class="el" href="group___c_a_n.html#ga157d49a9343dea68ac953145e02266d8">canRead()</a> returns.</p>
<p>When an error frame is received, its identifier, DLC and data bytes will be undefined. You should test if a message is an error frame before checking its identifier, DLC or data bytes.</p>
<p>In an healthy CAN system, error frames should rarely, if ever, occur. Error frames usually mean there is some type of serious problem in the system, such as a bad connector, a bad cable, bus termination missing or faulty, or another node transmitting at wrong bit rate, and so on.</p>
<h1><a class="anchor" id="section_user_guide_bus_errors_sja1000_error_codes"></a>
SJA1000 Error Codes</h1>
<p>Many of our CAN interface boards use the SJA1000 CAN controller. When an error occurs on the bus, the device firmware and driver will pass the error code from the CAN controller to the application by using the CAN identifier field. The identifier will be set to 0x800 (2048) plus the error code from the controller. The flag field will contain the <a class="el" href="canstat_8h.html#ade1b8ed815a4bc6ada6ec666e48e9cf8">canMSG_ERROR_FRAME</a> flag. The data length will be 0.</p>
<p>You can use the following tables to interpret the error code from the controller. Note that they are applicable only to those CAN interfaces that use SJA1000.</p>
<table class="doxtable">
<tr>
<th>Bit 7</th><th>Bit 6</th><th>Meaning </th></tr>
<tr>
<td>0</td><td>0</td><td>bit error </td></tr>
<tr>
<td>0</td><td>1</td><td>form error </td></tr>
<tr>
<td>1</td><td>0</td><td>stuff error </td></tr>
<tr>
<td>1</td><td>1</td><td>other type of error  </td></tr>
</table>
<p><br />
<br />
</p>
<table class="doxtable">
<tr>
<th>Bit 5</th><th>Meaning </th></tr>
<tr>
<td>0</td><td>TX; error occurred during transmission </td></tr>
<tr>
<td>1</td><td>RX; error occurred during reception </td></tr>
</table>
<p><br />
<br />
</p>
<table class="doxtable">
<tr>
<th>Bit 4..0</th><th>Meaning </th></tr>
<tr>
<td>0x03</td><td>start of frame </td></tr>
<tr>
<td>0x02</td><td>ID.28 to ID.21 </td></tr>
<tr>
<td>0x06</td><td>ID.20 to ID.18 </td></tr>
<tr>
<td>0x04</td><td>bit SRTR </td></tr>
<tr>
<td>0x05</td><td>bit IDE </td></tr>
<tr>
<td>0x07</td><td>ID.17 to ID.13 </td></tr>
<tr>
<td>0x0F</td><td>ID.12 to ID.5 </td></tr>
<tr>
<td>0x0E</td><td>ID.4 to ID.0 </td></tr>
<tr>
<td>0x0C</td><td>bit RTR </td></tr>
<tr>
<td>0x0D</td><td>reserved bit 1 </td></tr>
<tr>
<td>0x09</td><td>reserved bit 0 </td></tr>
<tr>
<td>0x0B</td><td>data length code </td></tr>
<tr>
<td>0x0A</td><td>data field </td></tr>
<tr>
<td>0x08</td><td>CRC sequence </td></tr>
<tr>
<td>0x18</td><td>CRC delimiter </td></tr>
<tr>
<td>0x19</td><td>acknowledge slot </td></tr>
<tr>
<td>0x1B</td><td>acknowledge delimiter </td></tr>
<tr>
<td>0x1A</td><td>end of frame </td></tr>
<tr>
<td>0x12</td><td>intermission </td></tr>
<tr>
<td>0x11</td><td>active error flag </td></tr>
<tr>
<td>0x16</td><td>passive error flag </td></tr>
<tr>
<td>0x13</td><td>tolerate dominant bits </td></tr>
<tr>
<td>0x17</td><td>error delimiter </td></tr>
<tr>
<td>0x1C</td><td>overload flag </td></tr>
</table>
<p><b>Example</b><br />
 <em>A message is transmitted on the CAN bus. A stream of error frames are returned. <a class="el" href="group___c_a_n.html#ga157d49a9343dea68ac953145e02266d8">canRead()</a> reads messages with id 0x000008D9, dlc = 0 and flags = 0x20 (<a class="el" href="canstat_8h.html#ade1b8ed815a4bc6ada6ec666e48e9cf8">canMSG_ERROR_FRAME</a>). What's up?</em></p>
<p>Using the tables above, we see that 0xD9 means</p><ul>
<li>Other type of error.</li>
<li>Error during transmit.</li>
<li>Acknowledge slot.</li>
</ul>
<p>so it is likely that the module transmitting the message doesn't get any answer.</p>
<dl class="section note"><dt>Note</dt><dd>We make no guarantee that this feature will be present in future releases of hardware, drivers and firmware.<br />
</dd>
<dd>
We recommend that you use this feature for troubleshooting a particular installation only. Do not write your software so it relies on this feature. </dd></dl>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_canlib.html">CAN bus API (CANlib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
